<template>
    <view>
        <view @click="echarts.onClick" :prop="option" :change:prop="echarts.updateEcharts" id="echarts" class="echarts">
			
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {}
        },
        props: ['option'],
        onLoad() {
        },
        methods: {
            onViewClick(options) {
                console.log(options)
            }
        }
    }
</script>

<script module="echarts" lang="renderjs">
    let myChart
    export default {
        mounted() {
			
            if (typeof window.echarts === 'function') {
                this.initEcharts()
				
            } else {
                // 动态引入较大类库避免影响页面展示
                const script = document.createElement('script')
                // view 层的页面运行在 www 根目录，其相对路径相对于 www 计算
                script.src = '/static/echarts.js'
				
                script.onload = this.initEcharts.bind(this)
                document.head.appendChild(script)
            }
        },
        methods: {
            initEcharts() {
				console.log(1111,echarts);
                myChart = echarts.init(document.getElementById('echarts'))
				console.log(111,myChart);
                // 观测更新的数据在 view 层可以直接访问到
				// setTimeout(() => {,800)}
				
                myChart.setOption(this.option)
            },
            updateEcharts(newValue, oldValue, ownerInstance, instance) {
                // 监听 service 层数据变更
				setTimeout(() => {myChart.setOption(newValue)},800)
                
            },
            onClick(event, ownerInstance) {
                // 调用 service 层的方法
                ownerInstance.callMethod('onViewClick', {
                    test: 'test'
                })
            }//## 标题
        }
    }
</script>

<style>
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }

    .echarts {
        /* margin-top: 100px; */
		/* position: relative;
		top: 0;
		left: 0; */
		display: flex;
        width: 750rpx;
        height: 300px;
    }
</style>
